﻿@{
    ViewBag.Title = "cedit";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/Base/Member.js")" type="text/javascript"></script>      
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>    
}

<form id="form1" method="post">
    @Html.Partial("~/Views/Modular/Toolbars.cshtml")
    <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%; height:100%; top: 0px; left: 0px;overflow:hidden;border:none;" plain="true"
         onactivechanged="changeTabs">
        <div name="Base" title="会员资料" style="height:100%;overflow:hidden;margin-top:5px;margin-left:35px;">
            <table style="border-collapse: collapse;left: 30px;">
                <tr>
                    <td width="80px" height="30px" align="right">会员分类：</td>
                    <td width="190px" height="30px">
                        @Html.Partial("~/Views/Modular/LookupMembersClass.cshtml")
                    </td>
                    <td width="80px" height="30px" align="right">性别：</td>
                    <td width="200px" height="30px">
                        <input id="FSex" name="FSex" class="mini-combobox" style="width:200px;" showNullItem="false"
                        allowInput="false" align="left" value="1" data="comSexType" tabindex="7" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">会员等级：</td>
                    <td width="200px" height="30px">
                        @Html.Partial("~/Views/Modular/LookupMemberRank.cshtml")
                    </td>
                    <td width="80px" height="30px" align="right">当前积分：</td>
                    <td width="200px" height="30px">
                        <input id="FPoint" name="FPoint" class="mini-spinner" enabled="false" value="0" showbutton="false"
                               style="width:200px;" align="right" minValue="-9999999" maxValue="999999999" TabIndex="8" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">会员卡号：</td>
                    <td width="200px" height="30px">
                        <input name="FNumber" id="FNumber" class="mini-textbox" style="width:200px;" required="true" value="" TabIndex="1" />
                    </td>
                    <td width="80px" height="30px" align="right">当前余额：</td>
                    <td width="200px" height="30px">
                        <input name="FAmount" id="FAmount" class="mini-spinner" enabled="false" showbutton="false"
                               style="width:200px;" align="right" minValue="-9999999" maxValue="999999999" value="0" TabIndex="9" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">会员姓名：</td>
                    <td width="200px" height="30px">
                        <input id="FName" name="FName" class="mini-textbox " style="width:200px;" required="true" TabIndex="2" />
                    </td>
                    <td width="80px" height="30px" align="right">折扣：</td>
                    <td width="200px" height="30px">
                        <input name="FDiscount" id="FDiscount" class="mini-spinner" minValue="0" maxValue="1" 
                            showbutton="false" style="width:70px;" align="right" value="1" TabIndex="10" />
                         如:0.9表示90%，即9折.
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">联系电话：</td>
                    <td width="200px" height="30px">
                        <input name="FPhone" id="FPhone" class="mini-textbox" style="width:200px;" required="true" value="" TabIndex="11" />
                    </td>
                    <td width="80px" height="30px" align="right">注册日期：</td>
                    <td width="200px" height="30px">
                        <input id="FCreateTime" name="FCreateTime" enabled="false" class="mini-datepicker " format="yyyy-MM-dd" style="width:200px;" tabindex="3" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">生效日期：</td>
                    <td width="200px" height="30px">
                        <input id="FStartTime" name="FStartTime" class="mini-datepicker" required="true" format="yyyy-MM-dd" style="width:200px;" tabindex="4" />
                    </td>
                    <td width="80px" height="30px" align="right">联系地址：</td>
                    <td width="200px" height="30px">
                        <input id="FAddress" name="FAddress" class="mini-textbox " style="width:200px;" TabIndex="12" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">失效日期：</td>
                    <td width="200px" height="30px">
                        <input id="FEndTime" name="FEndTime" class="mini-datepicker" required="true" format="yyyy-MM-dd" style="width:200px;" tabindex="5" />
                    </td>
                    <td width="80px" height="30px" align="right">电子邮箱：</td>
                    <td width="200px" height="30px">
                        <input name="FEmail" id="FEmail" class="mini-textbox" style="width:200px;" value="" TabIndex="13" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">会员生日：</td>
                    <td width="200px" height="30px">
                        <input id="FBirthday" name="FBirthday" class="mini-datepicker" format="yyyy-MM-dd" style="width:200px;" tabindex="6" />
                    </td>
                    <td width="80px" height="30px" align="right">备注：</td>
                    <td width="200px" height="30px">
                        <input id="FRemark" name="FRemark" class="mini-textbox " style="width:200px;" TabIndex="14" />
                    </td>
                </tr>
                <tr>
                    <td width="80px" height="30px" align="right">会员状态：</td>
                    <td>
                        <input id="FDeleted" name="FDeleted" class="mini-combobox" style="width:200px;" TabIndex="9" value="1" data="dState" />
                    </td>
                    <td width="80px" height="30px" align="right">介绍人：</td>
                    <td width="200px" height="30px">
                        @Html.Partial("~/Views/Modular/LookupMember.cshtml")
                    </td>
                </tr>
            </table>
            <table style="border-collapse: collapse;left: 30px;">
                <tr>
                    <td width="80px" height="30px" align="right">赊账额度：</td>
                    <td width="200px" height="30px">
                        <input name="FSheAmount" id="FSheAmount" class="mini-spinner" minValue="-99999999" maxValue="99999999"
                               showbutton="false" style="width:200px;" align="right" value="0" TabIndex="15" allowNull="true" />
                    </td>
                    <td width="30px"></td>
                    <td align="right" style="padding-right:20px;vertical-align:center;" height="30px"><div id="FAmountFlag" name="FAmountFlag" class="mini-checkbox" readOnly="false" text="可充值"></div></td>
                    <td align="left" height="30px" style="padding-left:2px;vertical-align:center;"><div id="FPointFlag" name="FPointFlag" class="mini-checkbox" readOnly="false" text="可积分"></div></td>
                    <td align="left" style="padding-left:20px;vertical-align:center;" height="30px">
                        <div id="FSheFlag" name="FSheFlag"
                             class="mini-checkbox" readOnly="false" text="可赊账" onvaluechanged="sheset"></div>
                    </td>
                </tr>
            </table>
            <br />
        </div>
        <div name="Taglist" title="会员标签" style="height:100%;overflow:hidden;margin-top:5px;">
            @Html.Partial("~/Views/Modular/TagEditBar.cshtml")
            <div id="Taggrid" class="mini-datagrid" style="width:100%;height:89%;" pageSize="15"
                 borderStyle="border:1;" url="GetGoodsSpecs" showPager="false" idField="FItemID"
                 allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"
                 sortMode="client">
                <div property="columns">
                    <div type="checkcolumn">选行</div>
                    <div header="编号" field="FItemID" width="80"  headeralign="center">编号</div>
                    <div field="FName" name="FName" width="220" headeralign="center">标签名</div>
                    <div field="FRemark" name="FRemark" width="150" headerAlign="center" align="left">备注</div>
                </div>
            </div>
        </div>
        <div name="TagOther" title="其它信息" style="height:100%;overflow:hidden;margin-top:5px;">
            <table style="border-collapse: collapse;left: 30px;">
                <tr>
                    <td width="80px" height="30px" align="right">电子会员ID：</td>
                    <td width="200px" height="30px">
                        <input name="fk_users_id" id="fk_users_id" class="mini-textbox" style="width:200px;" readonly="readonly"/>
                    </td>
                    <td width="80px" height="30px" align="right"></td>
                    <td width="200px" height="30px">

                    </td>
                </tr>
             </table>
        </div>
        <div name="TagWechat" title="小程序关联" style="height:100%;overflow:hidden;margin-top:5px;">
            <div id="WechatGrid" class="mini-datagrid" style="width:100%;height:89%;" pageSize="15"
                 borderStyle="border:1;" showPager="false" fitColumns="false">
                <div property="columns">
                    <div field="FItemID" name="FItemID" width="150" headerAlign="center" align="left">会员ID</div>
                    <div field="FUnionID" name="FUnionID" width="150" headerAlign="center" align="left">关联ID</div>
                    <div field="FCreateTime" name="FCreateTime" width="140px" dateFormat="yyyy-MM-dd HH:mm:ss" headerAlign="center">关注日期</div>
                    <div field="FPhone" name="FPhone" width="150" headerAlign="center" align="left">手机号</div>
                    <div field="FNiName" name="FNiName" width="150" headerAlign="center" align="left">昵称</div>
                </div>
            </div>
        </div>
        <div name="TagWxOpen" title="公众号关联" style="height:100%;overflow:hidden;margin-top:5px;">
            <div id="WeixinGrid" class="mini-datagrid" style="width:100%;height:89%;" pageSize="15"
                 borderStyle="border:1;" showPager="false" fitColumns="false">
                <div property="columns">
                    <div field="FItemID" name="FItemID" width="150" headerAlign="center" align="left">会员ID</div>
                    <div field="FUnionID" name="FUnionID" width="150" headerAlign="center" align="left">关联ID</div>
                    <div field="FCreateTime" name="FCreateTime" width="140px" dateFormat="yyyy-MM-dd HH:mm:ss" headerAlign="center">关注日期</div>                    
                    <div field="FNiName" name="FNiName" width="150" headerAlign="center" align="left">昵称</div>
                </div>
            </div>
        </div>
    </div>
    <input name="FItemID" class="mini-hidden" />
</form>
<script>
    var comSexType = [{ "id": "0", "text": "男" },
                       { "id": "1", "text": "女" }]

    var dState = [{ "id": "1", "text": "正常" },{ "id": "-2", "text": "停用" }];

    mini.parse();
    var wechatGrid = mini.get("WechatGrid");
    var weixinGrid = mini.get("WeixinGrid");
    function FormShown() {
        mini.getbyName("FAmountFlag").setValue(true);
        mini.getbyName("FPointFlag").setValue(true);
    }

    //加载资料
    function SetInfoData(dataArg) {
        if (dataArg.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            mini.getbyName("FItemID").setValue(0);
            mini.getbyName("FMembersClassID").setValue(dataArg.FClassID);
            mini.getbyName("FMembersClassID").setText(dataArg.FClassNumber);
            mini.getbyName("FMembersClassName").setValue(dataArg.FClassName);
            mini.getbyName("FDiscount").setValue(dataArg.FDiscount);
            mini.getbyName("FSheAmount").setValue(dataArg.FSheAmount);
            NewInfo();
            mini.getbyName("FAmountFlag").setValue(dataArg.FAmountFlag);
            mini.getbyName("FPointFlag").setValue(dataArg.FPointFlag);
            mini.getbyName("FSheFlag").setValue(dataArg.FSheFlag);
        }
        else {
            $.post("GetMember", { json: "[{'FItemID':'" + dataArg.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                mini.getbyName("FItemID").setValue(dataArg.FItemID);
                try
                {
                    form.setData(mdata.data[0]);
                    wechatGrid.setData(mdata.dataWechat);
                    weixinGrid.setData(mdata.dataWeixin);
                }
                catch (e) {
                }
                mini.getbyName("FAmountFlag").setValue(mdata.data[0].FAmountFlag);
                mini.getbyName("FPointFlag").setValue(mdata.data[0].FPointFlag);
                mini.getbyName("FSheFlag").setValue(mdata.data[0].FSheFlag);
                sheset();
                if (mini.getbyName("FCreateTime").getValue() != "") {
                    var date = new Date(mini.getbyName("FCreateTime").getValue());
                    var str = date;
                    mini.getbyName("FCreateTime").setValue(str);
                }
                mini.getbyName("FMembersClassID").setText(mdata.data[0].FMembersClassNumber);
                mini.getbyName("FMemberRankID").setText(mdata.data[0].FMemberRankNumber);
                mini.getbyName("FMemberNumber").setValue(mdata.data[0].FParentID);
                mini.getbyName("FMemberNumber").setText(mdata.data[0].FParentNumber);
                mini.getbyName("FMemberName").setValue(mdata.data[0].FParentName);

                for (var i = 0; i < mdata.data0.length; i++) {
                    AddTag(mdata.data0[i].FItemID, mdata.data0[i].FItemID, mdata.data0[i].FName);
                }
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("");
        mini.getbyName("FName").setValue("");
        mini.getbyName("FPhone").setValue("");
        mini.getbyName("FPoint").setValue("0");
        mini.getbyName("FAmount").setValue("0");
        mini.getbyName("FRemark").setValue("");
        mini.getbyName("FMemberNumber").setValue("");
        mini.getbyName("FMemberNumber").setText("");
        mini.getbyName("FMemberName").setValue("");
        var date = new Date();
        var str = (date.getFullYear()) + "-" + (date.getMonth() + 1) + "-" + date.getDate();
        mini.getbyName("FCreateTime").setValue(str);
        mini.getbyName("FStartTime").setValue(str);
        mini.getbyName("FEndTime").setValue('2099-01-01');
        var jsonstr = '{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}';
        $.post('NewMember', { json: jsonstr }, function (data) {
            mini.getbyName("FNumber").setValue(data);
        });
        $.post("GetMemberRank", { json: "[{'FItemID':0,'mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
            var mdata = mini.decode(data);
            if (mdata.data.length > 0) {
                mini.getbyName("FMemberRankID").setValue(mdata.data[0].FItemID);
                mini.getbyName("FMemberRankID").setText(mdata.data[0].FNumber);
                mini.getbyName("FMemberRankName").setValue(mdata.data[0].FName);
            }
        });
    }

    //保存资料
    function SaveInfo() {

        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) return;
        var data = form.getData(true, false);
        if (mini.getbyName("FSheFlag").getValue == "false")
            data.FSheAmount = 0;
        if (!valid(data)) 
            return;

        var taggrid = mini.get("Taggrid");
        var tagvalues = taggrid.getData();
        data.tagvalue = tagvalues;
        var json = mini.encode(data);
        
        $.post("SaveInfo", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
            }
            else {
                mini.alert("" + ret.error);
            }
        });
    }

    function valid(data) {
        if (data.FMemberRankID == '') {
            mini.alert('会员等级未选择。');
            return false;
        }
        if (data.FMembersClassID == '') {
            mini.alert('会员分类未选择。');
            return false;
        }
        if (data.FNumber == '') {
            mini.alert('会员卡号未输入。');
            return false;
        }
        if (data.FName == '') {
            mini.alert('会员名称未输入。');
            return false;
        }
        if (data.FPhone == '') {
            mini.alert('联系电话未输入');
            return false;
        }
        return true;
    }

    function sheset()
    {
        if (mini.getbyName("FSheFlag").getValue()=="true") {
            //$("#row9").show();
            mini.getbyName("FSheAmount").setEnabled(true);
        }
        else {
            mini.getbyName("FSheAmount").setEnabled(false);
            //$("#row9").hide();
        }
    }

    function changeTabs() {

    }

    function addtagInfo() {
        mini.open({
            url: "../GetItem/MultIndex",
            title: "会员标签选择", width: 730, height: 460,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", sTbName: "MemberTag", sSearchKey: '' };
                iframe.contentWindow.SetData(data);//打开GetItemID.js的SetData
            },
            ondestroy: function (action) {
                if (action!="close" && action.length > 0) {
                    for (var i = 0; i < action.length; i++) {
                        AddTag(action[i].FItemID, action[i].FNumber, action[i].FName);
                    }
                }
            }            
        });
    }

    function AddTag(FItemID, FNumber, FName) {
        var grid = mini.get("Taggrid");
            var r = grid.getData().length + 1;
            var row = {
                FItemID: FItemID, FNumber: FNumber, FName: FName
            };            grid.addRow(row, r);
        
    }

    function removetagInfo() {
        var grid = mini.get("Taggrid");
        var row = grid.getSelected();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        grid.removeRow(row, true);
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }

</script>
